/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Action.AccountSessionBeanLocal;
import Action.AdminSessionBeanLocal;
import Action.CategorySessionBeanLocal;
import Action.CustomerSessionBeanLocal;
import Action.EventSessionBeanLocal;
import Action.TicketsCatSessionBeanLocal;
import Action.TicketsSessionBeanLocal;
import Action.TicketsSumSessionBeanLocal;
import Entity.Account;
import Entity.Admin;
import Entity.Category;
import Entity.Customer;
import Entity.Event;
import Entity.Tickets;
import Entity.TicketsCategory;
import Entity.TicketsSummary;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Cyrax
 */
@ManagedBean
@RequestScoped
public class SearchBean {
    @EJB
    private AccountSessionBeanLocal accountSessionBean;

    @EJB
    private CustomerSessionBeanLocal customerSessionBean;
    @EJB
    private TicketsSumSessionBeanLocal ticketsSumSessionBean;
    @EJB
    private TicketsSessionBeanLocal ticketsSessionBean;
    @EJB
    private TicketsCatSessionBeanLocal ticketsCatSessionBean;
    @EJB
    private EventSessionBeanLocal eventSessionBean;
    @EJB
    private CategorySessionBeanLocal categorySessionBean;
    @EJB
    private AdminSessionBeanLocal adminSessionBean;

    private String key;
    private String searchType;

    /** Creates a new instance of SearchBean */
    public SearchBean() {
    }

    /**
     * @return the key
     */
    public String getKey() {
        return key;
    }

    /**
     * @param key the key to set
     */
    public void setKey(String key) {
        this.key = key;
    }

    /**
     * @return the searchType
     */
    public String getSearchType() {
        return searchType;
    }

    /**
     * @param searchType the searchType to set
     */
    public void setSearchType(String searchType) {
        this.searchType = searchType;
    }

    public List<Admin> getsearchAdmin() {
        List<Admin> ad = null;
//        if (searchType.equals("admin")) {

            ad = adminSessionBean.searchAdmin(key.toString());

//        }

        return ad;
    }

    public List<Customer> getsearchCustomer() {
        List<Customer> cu = null;
//        if (searchType.equals("customer")) {
            cu = customerSessionBean.searchCustomer(key.toString());
//        }
        return cu;
    }

    public List<TicketsSummary> getsearchTicketsSum() {
        List<TicketsSummary> tkSum = null;
        tkSum = ticketsSumSessionBean.searchTicketsSummary(key.toString());
        return tkSum;
    }

//    public List<Tickets> getsearchTickets() {
//        List<Tickets> tk = null;
//        tk = ticketsSessionBean.searchTickets(key.toString());
//        return tk;
//    }

    public List<Event> getsearchEvent() {
        List<Event> ev = null;
        ev = eventSessionBean.searchEvent(key.toString());
        return ev;
    }

    public List<TicketsCategory> getsearchTicketsCategory() {
        List<TicketsCategory> tkCat = null;
        tkCat = ticketsCatSessionBean.searchTicketsCategory(key.toString());
        return tkCat;
    }

    public List<Category> getsearchCategory() {
        List<Category> cat = null;
        cat = categorySessionBean.searchCategory(key.toString());
        return cat;
    }

    public List<Account> getsearchAccount()
    {
       List<Account> ac=null;
       ac=accountSessionBean.searchAccount(key.toString());
       return ac;
     }

    public String searchAllEasyTickets() {
        if (searchType.equals("admin")) {
            getsearchAdmin();
            return "searchAdmin";
        } else if (searchType.equals("customer")) {
           getsearchCustomer();
            return "searchCustomer";
        } else if (searchType.equals("event")) {
            getsearchEvent();
            return "searchEvent";
        } else if (searchType.equals("category")) {
            getsearchCategory();
            return "searchCategory";
        }else if (searchType.equals("ticketsSum")) {
            getsearchTicketsSum();
            return "searchTicketsSum";
        } else if (searchType.equals("ticketsCat")) {
            getsearchTicketsCategory();
            return "searchTicketsCat";
        } else if (searchType.equals("about")) {
            getsearchCustomer();
            return "searchAbout";
        } else if (searchType.equals("faq")) {
            getsearchCustomer();
            return "searchFaq";
        } else if (searchType.equals("contact")) {
            getsearchCustomer();
            return "searchContact";
        }
        else if (searchType.equals("account")) {
            getsearchAccount();
            return "searchAccount";
        }
        return "AdminHome";
    }
}
